<?php

namespace app\admin\controller;

use app\BaseController;
use app\admin\model\Banner as model_banner;
use app\Request;
use think\facade\View;
class Banner extends BaseController
{

    public function BannerType(){



        return \view('',['list'=>config('view.Banner_type')]);
    }

    public function lists(){

        $list=model_banner::lists(input('type_id'));
        $status=[
            1=>'显示',
            2=>'隐藏'
        ];
        $type=[
            1=>'图片',
            2=>'视频'
        ];


        return view('',['list'=>$list,'status'=>$status,'type'=>$type,'types'=>input('type_id')]);
    }


    public function edit(Request $request){


        $id= input('id');
        if($request->isPost() && $request->isAjax()){

            $id= input('id');

            empty($id) ? $type='add':$type='edit';
            if($type=='add'){
                $result= model_banner::insertbanner();
                return json($result);
            }else{

                $result= model_banner::modifybanner();
                return json($result);
            }
        }
        $info=model_banner::where(['id'=>$id])->find();

        if(!empty($info)){
            $url=config('filesystem.oss.'.$info->bucket);
            view::assign('url','https://'.$url);
        }


        empty($id) ? $tpl='add_banner':$tpl='edit_banner';

        return \view($tpl,['info'=>$info,'types'=>input('types')]);

    }

    public function BannerDel(){
        $result=model_banner::del();
        return $result;
    }



}